package com.abc.controller;

import com.abc.bean.User;
import com.abc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: bc
 * @Date: 2024-11-17 12:44
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public String login(String username, String password, HttpServletRequest request )
    {
        String rtv = userService.login(new User(null,username, password,0));
        if("登录成功".equals(rtv)){
            request.getSession().setAttribute("username",username);
        }
        return rtv;
    }
    @RequestMapping("/getUsername")
    public String getUsername(HttpServletRequest request )
    {
        if(request.getSession().getAttribute("username") == null){
            return "no";
        }
        return "ok";
    }
    //注册
    @RequestMapping("/register")
    public String register(String username, String password)
    {
        return userService.register(new User(null,username, password,0));
    }


}
